<template>
  <div class="myaddress">
    <div>
        <form action="/">
            <van-search
                v-model="value"
                show-action
                placeholder="请输入搜索关键词"
                @search="onSearch"
                @cancel="onCancel"
            />
        </form>
    </div>
    <div>
        <van-index-bar v-for="item in list" :key="item.id" @click="getselectvalue(item)">
        <van-index-anchor index="A" />
        <van-cell :title="item.city" />
        </van-index-bar>
    </div>
  </div>
</template>

<script>
import { getdetaildata } from "@/detail/detaildata.js";
export default{
    data(){
        return{
            list:[],
            cityvalue:"",
        }
    },
    methods:{
        onCancel(){
            this.$router.push("/hotel")
        },
        //请求数据
        fetchdata(){
            getdetaildata().then((res)=>{
                console.log(res.data)
                this.list=res.data.data
            })
        },
        //点击索引栏获取数据
        getselectvalue(item){
            console.log(item.city)
            this.cityvalue=item.city
            // console.log(this.cityvalue)
            this.$store.commit("getaddressdata",this.cityvalue)
            this.$router.push("/hotel")
        }
    },
    mounted(){
        this.fetchdata()
    },
}
</script>
